

class Solution(object):
    def nextGreaterElement(self, nums1, nums2):
        """
        :type nums1: List[int]
        :type nums2: List[int]
        :rtype: List[int]
        """
        # result = []
        # tem = []
        # for i in range(len(nums1)):
        #     for j in range(len(nums2)):
        #         if nums1[i] == nums2[j]:
        #             tem.append(j)
        # print(tem)
        # f = 0
        # for e in tem:
        #     while e+1 < len(nums2):
        #         if nums1[f] < nums2[e]:
        #             result.append(nums2[e])
        #             e += len(nums2)
        #         e += 1
        #     f += 1
        # print(result)
        m, n = len(nums1), len(nums2)
        res = [0] * m
        for i in range(m):
            j = nums2.index(nums1[i])
            k = j + 1
            while k < n and nums2[k] < nums2[j]:
                k += 1
            res[i] = nums2[k] if k < n else -1
        print(res)


if __name__ == '__main__':
    sol = Solution()
    sol.nextGreaterElement([4, 1, 2], [1, 3, 4, 2, 5])
